package com.wx.lambda.ii.chapter5;

public class SubThreadTest {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.exit(0);
        });
        thread.setDaemon(true); // 设置为守护线程
        thread.start();
        thread.setUncaughtExceptionHandler((t, e) -> {
            // 子线程退出异常处理，这里不做任何操作，避免影响主线程
            System.out.println("子线程退出"+e);
        });

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            // 在 JVM 即将关闭时执行的逻辑
            System.out.println("JVM is shutting down");
            while (true){}
        }));
        while (true){

        }


    }
}
